// xc_lshop/shop/user/barter/index.js

// import drawQrcode from '../../../../utils/weapp-qrcode.js';
// var barter_order = require('../../../model/barter_order')
var actmember = require('../../../../xc/model/member')

Page({
  mixins: [require('../../../../xc/mixins/basicMixin')],

  /**
   * 页面的初始数据
   */
  data: {
    show: false
  },
  itmnav(e){
   console.log(e)
   var item=e.currentTarget.dataset.item;
   if(item.cid==1){
     wx.navigateTo({
       url:item.url,
     })
   } 
  },
  xcloaddata: function (options, config) {
    var update = {};
    if (config.payment) {
      update["paymentconfig"] = config.payment
    }
    if (config.yihuo) {
      if (config.yihuo.status == 1) {
        update["yihuoconfig"] = config.yihuo
      } else {
        this.error("易货功能未开启", true)
      }
    }
    update['yihuoimg']=config.eg.yihuo
    // console.log("update")
    // console.log(config.eg.yihuo)
    this.setData(update)
  },

  scan() {
    var that = this;
    wx.scanCode({
      onlyFromCamera: false,
      success: function (reslut) {
        // console.log(reslut)
        // if( reslut['scanType']){
          wx.navigateTo({
            url: '/'+reslut['path'],
          })
        // }
       
      },
      fail: function (res) {


      },
      complete: function (com) {


      }
    })
  },
  afterlogin: function (options, config, userinfo) {
   

    this.updatesimplevipinfo(userinfo)
   
    if (userinfo.member_id == 0) { //未登录
      this.login()
    }
  },
  qrset1(uid) {
    this.setData({
      show: true
    })
    var code = "0100_" + uid;
    if (code) {
      drawQrcode({
        width: 200,
        height: 200,
        canvasId: 'myQrcode',
        text: code
      })
    }

  },
  qrset(){
    wx.navigateTo({
      url: '/xc_lshop/shop/user/barter/code',
    })
    return
    if(this.data.qrcode){
     this.setData({
       show:true
     })
     return
    }
    var that=this;
    actmember.getyihuoqrcode().then(function (res) {
      if (res["status"] == 1) {
        var updatemodel = {};
        updatemodel['qrcode']=res['url'];
        updatemodel['show']=true;

        that.setData(updatemodel);
       
        // that.aftergetuserinfo(that.data.member)
      
      } else {
        wx.showToast({
          icon: "error",
          title: '获取失败',
        })
      }
    })
  },
  updatesimplevipinfo(member) {
    var that = this;
    var updatemodel={}
    var unusedamount = 0;
    var hasamount = 0;
    actmember.simplevipinfo().then(function (res) {
      if (res["status"] == 1 && res["obj"]) {
        hasamount=res["obj"]["amount"];
        unusedamount=res["obj"]["unusedamount"];
        member.memberinfo.score = res["obj"]["score"]
        member.memberinfo.money = res["obj"]["money"]
        member.memberinfo.amount= res["obj"]["amount"]
        member.memberinfo.exp = res["obj"]["exp"]
        member.memberinfo.vipinfo = res["obj"]["vipinfo"]
        member.memberinfo.couponnum = res["obj"]["couponnum"]
        member.memberinfo.unusedamount= res["obj"]["unusedamount"]
        member.memberinfo.allactivaamount = res["obj"]["allactivaamount"]
      }
      updatemodel["member"] =member
      updatemodel["hasamount"] =hasamount
      updatemodel["unusedamount"] =unusedamount

      that.setData(updatemodel)
    })

  },
  onClose() {
    this.setData({
      show: false
    })
  },
  // 登录注册
  login() {
    var that = this;
    var app=getApp()
    app.xc_sys_config.authop.oppower("login").then(function (res) {
      that.setData({
        "member": app.globalData.member
      })
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },
 
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    var app = getApp()
    var sharetitle = this.shasretitle()

    var shareimg = this.data.shareimg


    var sharepath = ""
    if (this.data.sharepage) {


      sharepath = this.data.sharepage
      if (app.globalData.member && app.globalData.member.member_id) {
        sharepath = sharepath + "?shareid=" + app.globalData.member.member_id
      }
    } else {
      sharepath = app.xc_sys_config.getshareurl()
    }

    if(this.data.yihuoconfig.simg){
      shareimg=this.data.yihuoconfig.simg
    }
 
    return {
      title: sharetitle,
      path: sharepath,
      imageUrl:shareimg
    }
  }
})